<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script src="${ctx}/resources/js/jquery-1.11.1.js"></script>
<script src="${ctx}/resources/js/jquery.form.js"></script>

<script type="text/javascript">

	$(document).ready(function(){
		$('#userform').ajaxForm(function(){
			alert("谢谢提交！")
		});
	});
	function modify(id) {
		var jsonobj = $('#userform').serializeArray();//将表单转化为json对象
		var jsonstr = JSON.stringify(jsonobj);//将jsonobj转化为json字符串
		alert(jsonstr);
		$.ajax({
			type : 'put',
			contentType:'application/json;charset=UTF-8',
			url : '${ctx}/users/' + id,
			data: $('#userform').serializeArray(),
			dataType : 'json',
			success : function(data) {
				alert(data.success);
				//refresh();
			},
			error : function() {
				alert("error");
			}
		});
	}
</script>
<title>Users</title>
</head>
<body>


	<div>Spring mvc 表单</div>
	<form:form method="put" modelAttribute="user"
		action="${ctx}/users/${user.userid}">
		<table>
			<tr>
				<td>id</td>
				<td>用户名</td>
				<td>密码</td>
				<td>操作</td>
			</tr>
			<tr>
				<td><form:hidden path="userid" value="${user.userid}" /></td>
				<td><form:input path="username" value="${user.username}" /></td>
				<td><form:input path="password" value="${user.password}" /></td>
				<td><input type="submit" value="Save Changes" /></td>
			</tr>
		</table>
	</form:form>
	<div>普通表单</div>
	<form id="userform" name="userform" action="${ctx}/users/${user.userid}" method="post">
		<input type="hidden" id="userid" name="userid" value="${user.userid}">
		<table>
			<tr>
				<td>用户名</td>
				<td>密码</td>
				<td>操作</td>
			</tr>
			<tr>
				<td>用户名：<input type="text" id="username" name="username" value="${user.username}" ></td>
				<td>密码：<input type="password" id="password" name="password" value="${user.password}"></td>
				<td><input type="submit" value="保存修改" /></td>
			</tr>
		</table>
	</form>

</body>
</html>